<template>
  <el-dialog title="双击 选定收费路段" :visible.sync="visible" center>
    <el-container>
      <el-header >
        <el-col :xs="9" :sm="9" :lg="9">
          <el-input prefix-icon="el-icon-search" v-model="road_name" clearable placeholder="单位名称/单位名称拼音首字母"></el-input>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="12">
          <el-button type="primary" class="btn-search" @click="searchRoad" style="margin-left: 15px">查询</el-button>
        </el-col>
      </el-header>
      <el-main style="padding: 0">
        <el-table
          :data="tableData"
          stripe
          v-loading="roadLoading"
          @row-dblclick="selectRoad"
          highlight-current-row
          fit border
        height="300">
          <el-table-column
            prop="unitno"
            label="收费路段编号"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="parkname"
            label="所在停车场"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="sfdwname"
            label="收费单位"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="unitname"
            label="收费路段名称"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="placenum"
            label="泊位总数"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="statusname"
            label="收费路段状态"
            min-width="200">
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer>
        <el-pagination
          background
          layout="total,sizes,prev,pager,next,jumper"
          :total="total"
          :page-size="pageSize"
          :page-sizes="[10,20,30,50]"
          :current-page="pageNum"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          style="margin-top: 10px;"
        ></el-pagination>
      </el-footer>
    </el-container>
  </el-dialog>
</template>

<script>
  import { searchRoad } from '../../../api/public/searchUnit'
  import { selDictonaryValue } from '../../../api/dictionary'

  export default {
    name: 'person-child-dialog-road',
    data() {
      return {
        visible: false,
        road_name: '',
        tableData: [],
        pageNum: 1,
        total: 0,
        pageSize: 10
      }
    },
    props: ['dialogRoadVisible', 'roadLoading'],
    mounted: function() {
      this.visible = this.dialogRoadVisible
    },
    watch: {
      dialogRoadVisible: function(val) {
        this.visible = val
        if (val) {
          this.pageNum = 1
          this.pageSize = 10
          const $this = this
          searchRoad(1, this.pageSize, '').then(res => {
            selDictonaryValue(res).then(resp => {
              $this.tableData = resp.list
              $this.total = resp.count
              $this.pageSize = resp.pageSize
              $this.$emit('update:roadLoading', false)
            })
          })
        }
      },
      visible: function(val) {
        this.$emit('update:dialogRoadVisible', val)
      }
    },
    methods: {
      searchRoad: function() {
        const $this = this
        this.$emit('update:roadLoading', true)
        searchRoad(this.pageNum, this.pageSize, this.road_name).then(res => {
          selDictonaryValue(res).then(resp => {
            $this.tableData = resp.list
            $this.total = resp.count
            $this.pageSize = resp.pageSize
            $this.$emit('update:roadLoading', false)
          })
        })
      },
      selectRoad: function(row, event) {
        this.$emit('roadName', row)
        this.visible = false
      },
      handleCurrentChange: function(val) {
        this.pageNum = val
        this.searchRoad()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.searchRoad()
      }
    }
  }
</script>

<style scoped>
  .el-header{
    padding:0;
    border-bottom:none;
    margin-left: 5px;
  }
  .el-main{
    margin-top: 0px;
    margin-left: 5px;
  }
</style>
